package com.huabo.system.mysql.mapper;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.huabo.system.mysql.entity.TblSystemSheetTableMySql;
import com.huabo.system.oracle.entity.TblSystemSheetTable;

import tk.mybatis.mapper.common.BaseMapper;

public interface TblSystemSheetTableMySqlMapper extends BaseMapper<TblSystemSheetTableMySql> {

	@Insert("INSERT INTO TBL_SYSTEM_YMWORK(TABLEID, ORGID, YMWORKFROM, YMWORKNAME) VALUES (#{tableId}, #{orgid}, #{workId}, #{workName})")
	void InsertSystemYmWork(Integer tableId, String workId, BigDecimal orgid, String workName) throws Exception;

	@Update("UPDATE TBL_SYSTEM_YMWORK SET YMWORKNAME = #{workName} WHERE TABLEID = #{tableId} AND ORGID = #{orgid} AND YMWORKFROM = #{workId}")
	void UpdateSystemYmWork(Integer tableId, String workId, BigDecimal orgid, String workName);

	@SelectProvider(method="selectWorkFlowList",type=TblSystemSheetTableMySqlMapperSqlConfig.class)
	@Results({
		@Result(column="YMWORKFROM",property="ymWorkFrom"),
		@Result(column="YMWORKNAME",property="ymWorkName"),
	})
	List<TblSystemSheetTableMySql> selectWorkFlowList(Integer tableId, BigDecimal orgid, String workName) throws Exception;

	
	@SelectProvider(method="selectSystemFlowList",type=TblSystemSheetTableMySqlMapperSqlConfig.class)
	@Results({
		@Result(column="TABLEID",property="tableId"),
		@Result(column="YMWORKNAME",property="ymWorkName"),
		@Result(column="TABLETYPE",property="tableType"),
		@Result(column="WORKCOUNT",property="workCount"),
	})
	List<TblSystemSheetTableMySql> selectSystemFlowList(TblSystemSheetTable sheet) throws Exception;

	@Select("INSERT INTO TBL_SYSTEM_FORMFLOW(FORMID,FLOWID) VALUES (#{fromId}, #{flowId})")
	void insertFormFlowTable(String fromId, String flowId) throws Exception;

	@Select("SELECT COUNT(0) FROM TBL_SYSTEM_FORMFLOW WHERE FORMID = #{fromId}")
	Integer selectCountFormFlow(String fromId) throws Exception;

	@Update("UPDATE TBL_SYSTEM_FORMFLOW SET FLOWID = #{flowId} WHERE FORMID = #{fromId}")
	void updateFormFlowTable(String fromId, String flowId) throws Exception;

}
